<%--
  Created by IntelliJ IDEA.
  User: ZENG
  Date: 2021/8/19
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            width: 80%;
        }
    </style>
</head>
<body>
<%--清除浮动--%>
<div class="container">
    <%-- 分12列  12分之几--%>
    <div class="col-md-12 column">
        <div class="page-header">
            <h1>
                <small>添加书籍</small>
            </h1>
        </div>
    </div>
    <%--提交请求到此处--%>
    <form action="${pageContext.request.contextPath}/book/addBook" method="post" id="addBooks">
        <%--    name 要与实体类一致--%>
        <%--    required 空则不会跳转页面--%>
        <div class="form-group">
            <label>书籍名称:</label>
            <input type="text" name="bookName" class="form-control" required>
        </div>
        <div class="form-group">
            <label>书籍数量:</label>
            <div id="error" style="color: red"></div>
            <input type="text" id="booksNo" name="bookCounts" class="form-control" required>
        </div>
        <div class="form-group">
            <label>书籍描述:</label>
            <input type="text" name="detail" class="form-control" required>
        </div>
        <div class="form-group">
            <input type="submit" class="form-control" value="添加">
        </div>
    </form>
    <script type="text/javascript">
        document.getElementById("addBooks").onsubmit = function () {
            var regex1 = /^\d*$/;
            var bookNo = document.getElementById("booksNo").value;
            if (regex1.test(bookNo) == false) {
                document.getElementById("error").innerHTML = "请输入量";
                return false;
            } else {
                return true;
            }
        }

    </script>
</div>
</body>
</html>
